package com.example.basefream.service.impl;

import com.example.basefream.service.RetryService;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class RetryServiceImpl implements RetryService {

    @Transactional
    @Retryable(value = Exception.class, maxAttempts = 3, backoff = @Backoff(delay = 3000, multiplier = 1, maxDelay = 10000))
    @Override
    public void retryTransferAccounts(int fromAccountId, int toAccountId, float money) throws Exception {
        System.out.println("执行一次："+"==============");
        int a = 2 / 0;
        throw new Exception();
    }

    @Recover
    public void recover(Exception e) {
        System.out.println("回调方法执行！！！");
    }
}
